<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Dv_payments extends CI_Controller {

	     public function __construct()
       {
            parent::__construct();
		$this->load->helper("html");
		$this->load->helper("url");
		$this->load->helper('form');
		$this->load->helper('date');
		$this->load->model("dv_payments_model");
		$this->load->model("loads_model");
		//$this->load->model("guest_comment_model");
		//$this->load->model("news_events_model");
		//$this->load->model("roomcottages_model");
		$this->load->helper(array('form', 'url'));
		$this->load->database();
		
	}
	
	//START ------------------dv_payments---------------------
	function index()
	{
		$data['title']="Administrator Page";
		$data["list_dv_paymentss"] = $this->dv_payments_model->get_all_dv_payments();	
		$this->load->view('dv_payments_list_view',$data);
	}
function SearchLoadNo()
	{
		$data1["list_dv_paymentss"]=$this->dv_payments_model->getdvSearchByloadno($_POST['search']);
		$this->load->view('dv_payments_list_view',$data1);
	}
	function view_dv_payments()
	{
		$data['title']="Administrator Page";
		$code = $this->uri->segment(3);
		$data["list_dv_paymentss"] = $this->loads_model->getdv_payments_info($code);
		//$data["list_customers"] = $this->customers_model->getcustomers();
		$this->load->view('dv_payments_list_view',$data);
		
	}
	
	function add_dv_payments()
	{
		//$data["driver_dv_payments_data"] = $this->dv_payments_model->add_view_driver_dv_payments();
		$this->load->view('dv_payments_add_view');
	}
	
	function p_getinfo()
	{		
		$info = $this->loads_model->getloadInfoByLoadNo($_GET['load_no']);			
		$this->output->set_content_type('application/json');
    	$this->output->set_output(json_encode($info));
	}

	function p_add_dv_payments()
	{
		
		$this->load->database();			
		$load_no =$_POST['load_no'];
		$dv_company_name =$_POST['dv_company_name'];
		$n_name =$_POST['n_name'];
		$contract_amount =$_POST['contract_amount'];
		
		$advance1 =$_POST['advance1'];
		$type1 =$_POST['type1'];
		$date1 =$_POST['date1'];
		$reference1 =$_POST['reference1'];
		$ref_name1 =$_POST['ref_name1'];	
		$balance_ad1 =$_POST['balance_ad1'];			
		$advance2 =$_POST['advance2'];
		$type2 =$_POST['type2'];
		$date2 =$_POST['date2'];
		$reference2 =$_POST['reference2'];
		$ref_name2 =$_POST['ref_name2'];	
		$balance_ad2 =$_POST['balance_ad2'];					
		$detention_amnt =$_POST['detention_amnt'];
		$description_time =$_POST['description_time'];
		$lumpar =$_POST['lumpar'];
		$l_amount =$_POST['l_amount'];
		$description =$_POST['description'];	
		$dl_balance =$_POST['dl_balance'];	
		$f_amount =$_POST['f_amount'];			
		$f_type =$_POST['f_type'];			
		$f_date =$_POST['f_date'];			
		$f_reference =$_POST['f_reference'];					
		$f_balance =$_POST['fbalance'];

$loadinfo = $this->loads_model->getloadInfoByLoadNo($load_no);	
		if($loadinfo==null){							 
			$_sql="insert into loads(load_no,date,rep,bc_company_name,bc_confrm_no,bc_rate,pick_up_place,pick_up_city,pick_up_state,pick_up_date,drop_off_place,drop_off_city,drop_off_state,drop_off_date,dv_company_name,contract_amount,comment_box,file_path,file_confrm_no)";
			$_sql.="values('$load_no','$date','$rep','$bc_company_name','$bc_confrm_no','$bc_rate','$pick_up_place','$pick_up_city','$pick_up_state','$pick_up_date','$drop_off_place','$drop_off_city','$drop_off_state','$drop_off_date','$dv_company_name','$contract_amount','$comment_box','$file_path','$file_confrm_no')";
			$query = $this->db->query($_sql); 			
			$data["list_loads"] = $this->loads_model->get_all_loads();	
			$this->load->view('loads_list_view',$data);
		}
		else{			
			$data["data_exist"] = "[$load_no] - Load No. already exist.";	
			$this->load->view('loads_add_view',$data);		
		}
		
		$paymentinfo = $this->dv_payments_model->getpaymentInfoBypaymentNo($load_no);	
		if($paymentinfo==null){							 
									 
		$_sql="insert into vendor_payments(load_no,dv_company_name,n_name,contract_amount,advance1,type1,date1,reference1,ref_name1,balance_ad1,advance2,type2,date2,reference2,ref_name2,balance_ad2,detention_amnt,description_time,lumpar,l_amount,description,dl_balance,f_amount,f_type,f_date,f_reference,f_balance)";
		$_sql.="values('$load_no','$dv_company_name','$n_name','$contract_amount','$advance1','$type1','$date1','$reference1','$ref_name1','$balance_ad1','$advance2','$type2','$date2','$reference2','$ref_name2','$balance_ad2','$detention_amnt','$description_time','$lumpar','$l_amount','$description','$dl_balance','$f_amount','$f_type','$f_date','$f_reference','$f_balance)";
		$query = $this->db->query($_sql); 
		$data["list_dv_paymentss"] = $this->dv_payments_model->get_all_dv_payments();	
		$this->load->view('dv_payments_list_view',$data);

		}
		else{			
			$data["data_exists"] = "[$load_no] - Load No. already exist.";	
			$this->load->view('dv_payment_add_view',$data);		
		}

	/*	$dv_payments_id=$this->db->insert_id();
	 
		$_sql="insert into dv_payments_contract(dv_payments_id,contract_amount)";
		$_sql.="values($dv_payments_id,$contract_amt)";
		$query = $this->db->query($_sql); */
			
							
	}

	function edit_dv_payments()
	{
 	    $code = $this->uri->segment(3);
		$data["info"] = $this->dv_payments_model->getdv_payments_info($code);	
		$this->load->view('dv_payments_edit_view',$data);
	}
	
	function p_edit_dv_payments()
	{
		$this->load->database();
		$dv_payment_id= $_POST['hid_dv_payment_id'];
		$load_no =$_POST['load_no'];
		$dv_company_name =$_POST['dv_company_name'];
		$contract_amount =$_POST['contract_amount'];
		$advance1 =$_POST['advance1'];
		$type1 =$_POST['type1'];
		$date1 =$_POST['date1'];
		$reference1 =$_POST['reference1'];
		$ref_name1 =$_POST['ref_name1'];	
		$balance_ad1 =$_POST['balance_ad1'];			
		
		$advance2 =$_POST['advance2'];
		$type2 =$_POST['type2'];
		$date2 =$_POST['date2'];
		$reference2 =$_POST['reference2'];
		$ref_name2 =$_POST['ref_name2'];	
		$balance_ad2 =$_POST['balance_ad2'];			
		
		$detention_amnt =$_POST['detention_amnt'];
		$description_time =$_POST['description_time'];
		$lumpar =$_POST['lumpar'];
		$l_amount =$_POST['l_amount'];
		$description =$_POST['description'];	
		$dl_balance =$_POST['dl_balance'];	
		
		$f_amount =$_POST['f_amount'];			
		$f_type =$_POST['f_type'];			
		$f_date =$_POST['f_date'];			
		$f_reference =$_POST['f_reference'];					
		$f_balance =$_POST['f_balance'];
		//	$dv_payments_comment_box = $_POST['txtdv_payments_comment_box'];
		//	$contract_amt = $_POST['txtcontract_amt'];
			$query = $this->db->query("UPDATE vendor_payments SET 
														  	load_no='$load_no',
														  	dv_company_name='$dv_company_name',
 													  		contract_amount='$contract_amount',
														  	advance1='$advance1', 
															type1='$type1', 
															date1='$date1', 
															reference1='$reference1',
															ref_name1='$ref_name1',
															balance_ad1='$balance_ad1',
															advance2='$advance2',
															type2='$type2',
															date2='$date2',
															reference2='$reference2',
															ref_name2='$ref_name2',
															balance_ad2='$balance_ad2',															
															detention_amnt='$detention_amnt',
															description_time='$description_time',
															lumpar='$lumpar',
															l_amount='$l_amount',
															description='$description',
															dl_balance='$dl_balance',
															f_amount='$f_amount',
															f_type='$f_type',
															f_date='$f_date',
															f_reference='$f_reference',
															f_balance='$f_balance' where dv_payment_id=$dv_payment_id");
														  
		$data["list_dv_paymentss"] = $this->dv_payments_model->get_all_dv_payments();	
		$this->load->view('dv_payments_list_view',$data);		
	}
	
	
	function delete_dv_payments()
	{
		$this->load->database();		
		$code = $this->uri->segment(3);
		$query = $this->db->query("delete from dv_payments where dv_company_namede='$code'");
		
		$data["list_dv_paymentss"] = $this->dv_payments_model->get_all_dv_payments();	
		$this->load->view('dv_payments_list_view',$data);
	}
	//END ------------------dv_payments---------------------
	
	
	function logout()
	{
		
		//$this->load->library('session');
		//$this->session->sess_destroy();
		session_start();
		session_destroy();
		//echo $_SESSION['Administrator_log'];
		//unset($_SESSION['Administrator_log']);
		
			//$data["newsresult"] = $this->dv_payments_model->dv_payments_all_driver_dv_payments();
			$this->load->view('owner/admin_view');
	 
	}
 
}
?>